{{ partial "meta" . }}
{{ $title := .Title }}

<body class="default list">
	<header>
		<div class="contain">
			<a href="{{ .Site.BaseURL }}">← {{ T "goBack" }} <em>{{ .Site.Title }}</em></a>
			<div class="padding"></div>
			<div class="padding"></div>

			<h1 class="clean">{{ $title }}</h1>

			<!-- Status Marker Start -->
			<div class="padding-s"></div>
			{{/* Collect all unresolved incidents for this component */}}
			{{ $incidents := where .Site.RegularPages "Params.section" "issue" }}
			{{ $active := where $incidents "Params.resolved" "=" false }}
			{{ $componentIssues := where $active "Params.affected" "intersect" (slice $title) }}

			{{ $isDown := where $componentIssues "Params.severity" "=" "down" }}
			{{ $isDisrupted := where $componentIssues "Params.severity" "=" "disrupted" }}
			{{ $isMaintenance := where $componentIssues "Params.severity" "=" "notice" }}

			{{ if gt (len $isDown) 0 }}
			<strong style="color: {{ .Site.Params.down }}">■ {{ T "thisIsDown" }}</strong>
			{{ else if gt (len $isDisrupted) 0 }}
			<strong style="color: {{ .Site.Params.disrupted }}">▲ {{ T "thisIsDisrupted" }}</strong>
			{{ else if gt (len $isMaintenance) 0 }}
			<strong style="color: {{ .Site.Params.notice }}">◆ {{ T "thisIsMaintenance" }}</strong>
			{{ else }}
			<strong style="color: {{ .Site.Params.ok }}">◆ {{ T "thisIsOk" }}</strong>
			{{ end }}
			<div class="padding-s"></div>
			<!-- Status Marker End -->

			{{ range .Site.Params.systems }}
			{{ if eq .name $title }}
			{{ with .description }}
			{{ . | markdownify }}
			{{ end }}
			{{ end }}
			{{ end }}

			{{ if .Content }}
			<div class="padding"></div>
			<div class="archive__head">
				{{ .Content }}
			</div>
			<div class="padding"></div>
			{{ end }}

			{{ if not .Site.Params.disableComplexCalculations }}
			<p class="bold">
				<em>
					{{ $resolved := first 5 (where .Pages "Params.resolved" "=" true) }}
					{{ if gt $resolved 0 }}
					{{ $.Scratch.Set "counter" 0 }}
					{{ range $resolved }}
					{{ $t := (time .Params.ResolvedWhen) }}
					{{ $timeDiff := (sub $t.Unix .Date.Unix) }}
					{{ $diffInMin := (div $timeDiff 60) }}
					{{ $.Scratch.Set "counter" (add ($.Scratch.Get "counter") $diffInMin) }}
					{{ end }}

					{{ T "averageSystemsDowntime" }}
					{{ div ($.Scratch.Get "counter") (len $resolved) }}
					{{ T "averageSystemsDowntimeSecondPart" }}
					{{ end }}
				</em>
			</p>
			{{ end }}

			<small class="faded">{{ len .Pages }} {{ T "entries" }}, {{ T "newestToOldest" }}</small>

			<div class="padding"></div>
			<hr class="clean">
		</div>
		{{ $incidents := .Pages }}
	</header>

	<div class="contain contain--more" id="incidents">
		{{ if not $incidents }}
		<div class="padding"></div>
		<h3>{{ T "calmBeforeTheStorm" }}</h3>
		<p>{{ T "noIncidentsDesc" }}</p>
		<div class="padding"></div>
		<div class="padding"></div>
		<div class="padding"></div>
		{{ else }}
		{{ $paginator := .Paginate $incidents .Site.Params.incidentPostsPerPage }}
		{{ range $paginator.Pages }}
		{{ .Render "small" }}
		{{ end }}

		{{ if gt $paginator.TotalPages 1 }}
		<hr>
		<div class="center">
			{{ if $paginator.HasPrev }}
			<a href="{{ $paginator.Prev.URL }}#incidents">
				← &nbsp; {{ T "prev" }}
			</a>
			{{ else }}
			<span class="faded">
				← &nbsp; {{ T "prev" }}
			</span>
			{{ end }}

			&nbsp; &nbsp;
			{{ $paginator.PageNumber }} / {{ $paginator.TotalPages }}
			&nbsp; &nbsp;

			{{ if $paginator.HasNext }}
			<a href="{{ $paginator.Next.URL }}#incidents">
				{{ T "next" }} &nbsp; →
			</a>
			{{ else }}
			<span class="faded">
				{{ T "next" }} &nbsp; →
			</span>
			{{ end }}
		</div>
		{{ end }}
		{{ end }}
		<div class="padding"></div>
	</div>

	{{ partial "js" . }}
	{{ partial "footer" . }}
</body>

</html>